<?php
class Filmnews_Model extends Model {
	function __construct()
  	{
  		parent::Model();
  	}
  	function rename($details,$id){
 	 $oldname='assets/filmnews/'.$details['upload_data']['file_name'];
 	 rename($oldname,'assets/filmnews/film_img'.$id.'.jpg');
  	}
  	function select($id="",$limit="",$order="",$count=false){
  		//echo $limit;
  	if($id!="")
  	{
  		$this->db->where('id', $id);
  	}		
  	if($order!="")
  	{
  	 $this->db->order_by('id','desc');
  	}
  	if($count==false)
  	 	{
  	  	if(isset($limit) && $limit>=0 )
  	   		{
  	  			$this->db->limit(10,$limit);
  	    	} 
  	}
  	$details=$this->db->get('film_news');
  	if($count==true)
    	return $details->num_rows();
     else
		return $details->result();
  	}
  	function news_more($id){
  		$id1=array('id'=>$id);
  		$details=$this->db->get_where('film_news',$id1);
  		//print_r($details->result());
  		return $details->result();
  	}
  	function get_filmnews_headings(){
  		$this->db->order_by('id','desc');
  		$details=$this->db->get('film_news');
  		return $details->result();
  	}
  	function get_breaking_news(){
  		$array=array('breaking_news'=>'1');
  		$details=$this->db->get_where('film_news',$array);
  		return $details->result();
  	}

    function delete($id)
    {
    	$remove=array();
    	if(isset($_POST['remove']))
    	{
    		$remove = $_POST['removeid'];
    		
    	}
    	else {
    		$remove = array($id);
    	}
    	foreach($remove as $item)
    	{
    		$this->db->where('id',$item);
    		$this->db->delete('film_news');
    		unlink('./assets/filmnews/film_img'.$item.'.jpg');
    		unlink('./assets/filmnews/film_img'.$item.'_thumb.jpg');
    	}
    }
    function getdetails($id)
    {
    	$this->db->where('id',$id);
    	$query = $this->db->get('film_news');
    	return $query->result();
    }	
    function edit1($id,$breaking)
    {
    	
        
    	$data=array('heading'=>$_POST['heading'],
  					'summery'=>$_POST["summary"],
  					'description'=>$_POST["description"],
  					'breaking_news'=>$breaking
  					);
  		$this->db->where('id',$id);	
  		$this->db->update('film_news',$data);		
    }
}
?>